<?php
class Default_Model_DbTable_ObjectDetail extends Zend_Db_Table_Abstract {
	protected $_name = 'object_detail';
	public function addObjectDetail($object_id, $logo, $title, $short_description, $long_description, $status) {
		$data = array (
				'OBJECT_ID' => $object_id,
				'LOGO' => $logo,
				'TITLE' => $title,
				'SHORT_DESCRIPTION' => $short_description,
				'LONG_DESCRIPTION' => $long_description,
				'STATUS' => $status 
		);
		return $this->insert ( $data );
	}
	public function updateObjectDetail($id, $object_id, $logo, $title, $short_description, $long_description, $status) {
		$data = array (
				'OBJECT_ID' => $object_id,
				'LOGO' => $logo,
				'TITLE' => $title,
				'SHORT_DESCRIPTION' => $short_description,
				'LONG_DESCRIPTION' => $long_description,
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function removeObjectDetail($id) {
		return $this->delete ( "ID = $id" );
	}
	public function updateStatus($id, $status) {
		$data = array (
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function activeObjectDetail($id) {
		$lv = $this->fetchRow ( "ID = $id" );
		if ($lv ["STATUS"] == 1) {
			$this->update ( array (
					"STATUS" => 0 
			), "ID = $id" );
		} else {
			$this->update ( array (
					"STATUS" => 1 
			), "ID = $id" );
		}
	}
	public function getAllObjectDetail() {
		return $this->fetchAll ()->toArray ();
	}
	public function getObjectDetailById($id) {
		$select = $this->select ( Zend_Db_Table::SELECT_WITH_FROM_PART )->setIntegrityCheck ( false );
		
		$rows = NULL;
		
		$select->from ( "object_detail AS od", array (
				"od.ID",
				"od.LOGO",
				"od.TITLE",
				"od.SHORT_DESCRIPTION",
				"od.LONG_DESCRIPTION",
				"od.STATUS" 
		) )->where ( "od.STATUS = ?", 1 )->join ( "object AS o", "o.ID = od.OBJECT_ID", array (
				"o.OBJECT_NAME" 
		) )->where ( "od.ID= ?", $id );
		try {
			$rows = $this->fetchRow ( $select );
		} catch ( Exception $e ) {
			print_r ( $e );
		}
		return $rows->toArray ();
	}
	public function getObjectDetailByObjectId($object_id) {
		$select = $this->select ( Zend_Db_Table::SELECT_WITH_FROM_PART )->setIntegrityCheck ( false );
		
		$rows = NULL;
		
		$select->from ( "object_detail AS od", array (
				"od.ID",
				"od.LOGO",
				"od.TITLE",
				"od.SHORT_DESCRIPTION",
				"od.LONG_DESCRIPTION",
				"od.STATUS" 
		) )->where ( "od.STATUS = ?", 1 )->join ( "object AS o", "o.ID = od.OBJECT_ID", array (
				"o.OBJECT_NAME" 
		) )->where ( "od.OBJECT_ID= ?", $object_id );
		try {
			$rows = $this->fetchAll ( $select );
		} catch ( Exception $e ) {
			print_r ( $e );
		}
		return $rows->toArray ();
	}
	public function getObjectDetailByObjectName($object_name) {
		$select = $this->select ( Zend_Db_Table::SELECT_WITH_FROM_PART )->setIntegrityCheck ( false );
		
		$rows = NULL;
		
		$select->from ( "object_detail AS od", array (
				"od.ID",
				"od.LOGO",
				"od.TITLE",
				"od.SHORT_DESCRIPTION",
				"od.LONG_DESCRIPTION",
				"od.STATUS" 
		) )->where ( "od.STATUS = ?", 1 )->join ( "object AS o", "o.ID = od.OBJECT_ID", array (
				"o.OBJECT_NAME" 
		) )->where ( "o.OBJECT_NAME= ?", $object_name );
		try {
			$rows = $this->fetchAll ( $select );
		} catch ( Exception $e ) {
			print_r ( $e );
		}
		return $rows->toArray ();
	}
}

